var express = require('express');
var router = express.Router();
const fetch = require('../Crawler/index')
const lagouFetch = require('../Crawler/lagou')
const dataHand = require('../Datahand/index')
console.log(dataHand)
async function getCrawFetch(number, cityId, ) {
  return await fetch(number, cityId)
}
async function getLagouFetch() {
  return await lagouFetch()
}
// const result = getCrawFetch(10)
/* GET home page. */
router.get('/', async function(req, res, next) {
  // res.header("Content-Type", "text/html; charset=utf-8")
  //console.log(await result)
  const data = await result
  // console.log(dat
  const msg = dataHand.fiveone(data)
  res.send(msg)
});

router.post('/', async function(req, res, next) {
  // res.header("Content-Type", "text/html; charset=utf-8")
  //console.log(await result)
  console.log(req.body.id, 'asdasdsadasd')
  const result = await getCrawFetch(50, req.body.id)
  const data = await result
  // console.log(dat
  console.log(`共爬取到 ${data.length} 的数据`)
  const msg = dataHand.fiveone(data)
  res.send(msg)
});


module.exports = router;